<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>消息中心_win</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<style>
		.aui-tab-nav {
			background-color: #F3F3F3;
		}
	</style>
</head>
<body>
    <header class="aui-bar aui-bar-nav aui-bar-primary" id="aui-header">
	    <a class="aui-pull-left" tapmode onclick="api.closeWin()">
	        <span class="aui-iconfont aui-icon-left"></span>返回
	    </a>
        <div class="aui-title">消息中心</div>
        <a class="aui-iconfont aui-icon-menu aui-pull-right"></a>
    </header>
    <div class="aui-tab" id="aui-tab">
        <ul class="aui-tab-nav" id="aui-tab-nav">
            <li tapmode onclick="typeSwitch(this, 'notice_atme_list', 0)" data-frmname="notice_atme_list" class="active" id="type0">@我<em id="atmeCount"></em></li>
            <li tapmode onclick="typeSwitch(this, 'notice_review_list', 1)" data-frmname="notice_review_list" id="type1">评论<em id="reviewCount"></em></li>
            <li tapmode onclick="typeSwitch(this, 'notice_msg_list', 2)" data-frmname="notice_msg_list" id="type2">私信<em id="msgCount"></em></li>
            <li tapmode onclick="typeSwitch(this, 'notice_newfans_list', 3)" data-frmname="notice_newfans_list" id="type3">粉丝<em id="newFansCount"></em></li>
            <li tapmode onclick="typeSwitch(this, 'notice_newlike_list', 4)" data-frmname="notice_newlike_list" id="type4">赞过我<em id="newLikeCount"></em></li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/OSChinaApi.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
	var nowTabIndex = 0;

    apiready = function(){
    	var pageParam = api.pageParam;
        var header = $api.byId('aui-header');
        $api.fixStatusBar(header); 
        var headerPos = $api.offset(header);
		var auiTab = $api.byId('aui-tab');
		var auiTabPos = $api.offset(auiTab);
		
		setTabCount();
		
		var initialIndex = getInitialIndex();
		api.openFrameGroup ({
            name: 'notice',
            scrollEnabled:true,
            rect:{
				x:0,             //左上角x坐标
				y:headerPos.h + auiTabPos.h,             //左上角y坐标
				w:'auto',           //宽度，若传'auto'，页面从x位置开始自动充满父页面宽度
				h:'auto',          //高度，若传'auto'，页面从y位置开始自动充满父页面高度
			},
            index: initialIndex,
            preload: 0,
            frames:
            [{
                name: 'notice_atme_list', 
                url: './notice_atme_list.html', 
                bounces:true,
                scrollToTop:false
            },{
                name: 'notice_review_list', 
                url: './notice_review_list.html', 
                bounces:true,
                scrollToTop:false
            },{
                name: 'notice_msg_list', 
                url: './notice_msg_list.html', 
                bounces:true,
                scrollToTop:false
            },{
                name: 'notice_newfans_list', 
                url: './notice_newfans_list.html', 
                bounces:true,
                scrollToTop:false
            },{
                name: 'notice_newlike_list', 
                url: './notice_newlike_list.html', 
                bounces:true,
                scrollToTop:false
            }]
        }, function(ret, err){
	        var aui_tab_nav = $api.byId('aui-tab-nav');
	        var aui_tab_nav_act = $api.dom(aui_tab_nav, '.aui-tab-nav li.active');
	        $api.removeCls(aui_tab_nav_act, 'active');
	        
            var name = ret.name;
            var index = ret.index;
            
            nowTabIndex = index;
            
			$api.addCls($api.byId('type'+index), 'active');
	        // iOS点击状态栏可返回顶部
			$("ul li").each(function(index){
				var frmname = $(this).data("frmname");
				api.setFrameAttr({
				    name: frmname,
				    scrollToTop: false
				});
			});
			api.setFrameAttr({
			    name: name,
			    scrollToTop: true
			});
			
        });
    };
    
    function typeSwitch(obj, name, index){
    
    	// 返回顶部(由于用了双重 openFrameGroup ，导致 openFrameGroup 的 scrollToTop:true 失效了，所以用js手动实现)
    	if(index == nowTabIndex){
			api.execScript({
			    name: 'notice_win',
			    frameName: name,
			    script: 'scroll();'
			});
    	}
    
        var aui_tab_nav = $api.byId('aui-tab-nav');
        var aui_tab_nav_act = $api.dom(aui_tab_nav, '.aui-tab-nav li.active');
        $api.removeCls(aui_tab_nav_act, 'active');
        $api.addCls(obj, 'active');
        api.setFrameGroupIndex({
            name: 'notice',
            index: index
        });
        
        // iOS点击状态栏可返回顶部
		$("ul li").each(function(index){
			var frmname = $(this).data("frmname");
			api.setFrameAttr({
			    name: frmname,
			    scrollToTop: false
			});
		});
		api.setFrameAttr({
		    name: name,
		    scrollToTop: true
		});
    }
    
	// 获取首次加载时，打开的标签页
	function getInitialIndex(){
		var index = 0;
		var notice_atmeCount 	=  parseInt( $api.getStorage('notice_atmeCount') );
		var notice_reviewCount 	=  parseInt( $api.getStorage('notice_reviewCount') );
		var notice_msgCount 	=  parseInt( $api.getStorage('notice_msgCount') );
		var notice_newFansCount =  parseInt( $api.getStorage('notice_newFansCount') );
		var notice_newLikeCount =  parseInt( $api.getStorage('notice_newLikeCount') );
		if( notice_atmeCount>0 ){
			index = 0;
		}else if( notice_reviewCount>0 ){
			index = 1;
		}else if( notice_msgCount>0 ){
			index = 2;
		}else if( notice_newFansCount>0 ){
			index = 3;
		}else if( notice_newLikeCount>0 ){
			index = 4;
		}
		return index;
	}
	
	// 设置各个选项卡上的新通知数
	function setTabCount(){
		var notice_atmeCount 	=  parseInt( $api.getStorage('notice_atmeCount') );
		var notice_reviewCount 	=  parseInt( $api.getStorage('notice_reviewCount') );
		var notice_msgCount 	=  parseInt( $api.getStorage('notice_msgCount') );
		var notice_newFansCount =  parseInt( $api.getStorage('notice_newFansCount') );
		var notice_newLikeCount =  parseInt( $api.getStorage('notice_newLikeCount') );
		
		if( notice_atmeCount>0 ){
			$api.text($api.byId('atmeCount'), '(' + notice_atmeCount + ')');
		}else{
			$api.text($api.byId('atmeCount'), '');
		}

		if( notice_reviewCount>0 ){
			$api.text($api.byId('reviewCount'), '(' + notice_reviewCount + ')');
		}else{
			$api.text($api.byId('reviewCount'), '');
		}

		if( notice_msgCount>0 ){
			$api.text($api.byId('msgCount'), '(' + notice_msgCount + ')');
		}else{
			$api.text($api.byId('msgCount'), '');
		}

		if( notice_newFansCount>0 ){
			$api.text($api.byId('newFansCount'), '(' + notice_newFansCount + ')');
		}else{
			$api.text($api.byId('newFansCount'), '');
		}

		if( notice_newLikeCount>0 ){
			$api.text($api.byId('newLikeCount'), '(' + notice_newLikeCount + ')');
		}else{
			$api.text($api.byId('newLikeCount'), '');
		}
	}
</script>
</html>